package com.time.company.components.popup;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.time.company.R;
import com.time.company.base.BasePW;

/**
 * Author: Created by deng on 2016/8/16.
 * E-mail: tx16bing@163.com
 */
public class ExitEditPW extends BasePW implements View.OnClickListener {

    private Context mContext;
    private TextView tvTip, tvLeft, tvRight;

    public ExitEditPW(Context context, ViewGroup view) {
        mContext = context;
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View mView = inflater.inflate(R.layout.pw_exit_edit, view, false);
        assignViews(mView);
        setContentView(mView);
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        setFocusable(true);
        setOutsideTouchable(true);
//        this.setAnimationStyle(R.style.CsbBank_Pw_Bottom_Animation);
        ColorDrawable dw = new ColorDrawable(0x80000000);
        this.setBackgroundDrawable(dw);
        mView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                dismiss();
                return true;
            }
        });
    }

    public void setTip(String tip) {
        if (!TextUtils.isEmpty(tip)) {
            tvTip.setText(tip);
        }
    }

    public void setLeft(String left) {
        if (!TextUtils.isEmpty(left)) {
            tvLeft.setText(left);
        }
    }

    public void setRight(String right) {
        if (!TextUtils.isEmpty(right)) {
            tvRight.setText(right);
        }
    }

    private void assignViews(View mView) {
        tvTip = mView.findViewById(R.id.tv_exit_tip);
        tvLeft = mView.findViewById(R.id.tv_exit_left);
        tvRight = mView.findViewById(R.id.tv_exit_right);
        tvLeft.setOnClickListener(this);
        tvRight.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (onItemClickListener != null) {
            if (view.getId() == R.id.tv_exit_right) {
                onItemClickListener.onItemClick(11, "");
                dismiss();
            } else {
                dismiss();
            }
        }
    }

}
